import Vue from 'vue'
import App from './App'
import Json from './Json' //测试用数据
import store from './store'
import common from './common/common.js'

const msg = (title, icon='none')=>{
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration:1500,
		mask:true,
		icon
	});
}
const json = type=>{
	//模拟异步请求数据
	return new Promise(resolve=>{
		setTimeout(()=>{
			resolve(Json[type]);
		}, 500)
	})
}

const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}
const ajax = (url,data,callfun,okfun)=>{
	//let baseurl='http://192.168.120.116:4911/api/circle/';
	let baseurl='https://lss.feiyit.net/api/circle/';
	uni.request({
		url: baseurl+url,
		dataType: 'json',
		method:'POST',
		data: data
	}).then(res => {
		callfun(res);
	}).catch(err => {
		uni.showModal({
			content: err.errMsg,
			showCancel: false
		});	
		if (okfun) okfun(err);
	});
}

Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.os = common;
Vue.prototype.$api = {msg, json, prePage,ajax};

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)
Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
